package com.itheima.controller;

import com.itheima.pojo.Brand;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/brands")
public class BrandController {


    @DeleteMapping("/id")
    @ResponseBody
    public String delete(Integer id){
        System.out.println("id="+id);
        return "delete ok";
    }

    @PostMapping
    @ResponseBody
    public String save(Brand brand){
        System.out.println(brand);
        return "ok";
    }


    @GetMapping("/id/{id}")
    @ResponseBody
    public Brand findById(@PathVariable Integer id){
        Brand brand = new Brand();
        brand.setId(id);
        brand.setBrandName("黑马");
        brand.setCompanyName("传智");
        return brand;
    }

    @GetMapping
    @ResponseBody
    public List findAll(){
        ArrayList<Brand> brands = new ArrayList<>();
        Brand brand = new Brand();
        brand.setId(1);
        brand.setBrandName("黑马");
        brand.setCompanyName("传智");
        brands.add(brand);
        brands.add(brand);
        brands.add(brand);
        return brands;

    }
}
